var fetch = require('isomorphic-fetch') ;

//非简单请求用例
var body={ phone:'18205960269', sign: 'xiaodao',code:694954,password:960269,time:'2017-09-26' };
fetch('http://www.xiaodao7887.com/boss/getBusInfo',{
    method: 'POST',
    mode: 'cors',
    headers: {
        'Content-Type': 'application/json'
    },
    body:JSON.stringify(body)
}).then(function(response) {
        if (response.status >= 400) {
            throw new Error("Bad response from server");
        }
        return response.json();
    })
    .then(function(stories) {
        console.log("stories",stories);
    });


return
var JPush = require('jpush-sdk')

var client = JPush.buildClient('f8e24c45505df69b4e464382', '51557c8d9b7fb986319898f7')

// function android (alert, title, builder_id, extras, priority, category, style, value, alertType)
var info = {msg:"勇哥收推送",info:[{key:"血压",value:"500"},{key:"体温",value:"37.5"}],img:"http://img.1985t.com/uploads/attaches/2017/08/129394-rzbOTOp.jpg"}
//info = JSON.stringify(info);

client.push().setPlatform('ios', 'android')
    //.setAudience(JPush.ALL)
    .setAudience(JPush.alias('18695611291','18205960269','13600809605'))
    .setNotification("標題", JPush.ios(info)
        ,JPush.android("勇哥收推送" , null, 1,info)
      //  ,JPush.android('高宇收到没' , null, 1,null,null,null,3,"http://img.1985t.com/uploads/attaches/2017/08/129394-rzbOTOp.jpg",null)
    )
  //  .setMessage('msg content')
   // .setOptions(null, 60)
    .send(function (err, res) {
        if (err) {
            if (err instanceof JPush.APIConnectionError) {
                console.log(err.message)
                // Response Timeout means your request to the server may have already received,
                // please check whether or not to push
                console.log(err.isResponseTimeout)
            } else if (err instanceof JPush.APIRequestError) {
                console.log(err.message)
            }
        } else {
            console.log('Sendno: ' + JSON.stringify(res))
            console.log('Msg_id: ' + res.msg_id)
        }
    })

return


client.getTagList(function (err, res) {
    if (err) {
        if (err instanceof JPush.APIConnectionError) {
            console.log(err.message)
        } else if (err instanceof JPush.APIRequestError) {
            console.log(err.message)
        }
    } else {
        console.log('getTagList :')
        console.log('got result:' + res.tags)
    }
})


return;
client.getDeviceTagAlias('0900e8d85ef', function (err, res) {
    if (err) {
        if (err instanceof JPush.APIConnectionError) {
            console.log(err.message)
        } else if (err instanceof JPush.APIRequestError) {
            console.log(err.message)
        }
    } else {
        console.log('getDeviceTagAlias :')
        console.log(res.alias)
        console.log(res.tags)
    }
})

var tagsToAdd = ['tag1', 'tag2']

client.updateDeviceTagAlias('171976fa8a8085fcdba', 'alias1', false, tagsToAdd, [],
    function (err, res) {
        if (err) {
            if (err instanceof JPush.APIConnectionError) {
                console.log(err.message)
            } else if (err instanceof JPush.APIRequestError) {
                console.log(err.message)
            }
        } else {
            console.log('updateDeviceTagAlias :' + res)
            console.log('success')
        }
    })

client.getTagList(function (err, res) {
    if (err) {
        if (err instanceof JPush.APIConnectionError) {
            console.log(err.message)
        } else if (err instanceof JPush.APIRequestError) {
            console.log(err.message)
        }
    } else {
        console.log('getTagList :')
        console.log('got result:' + res.tags)
    }
})

var toAddUsers = ['18071adc030dd6faa56', '171976fa8a8085fcdba']
var toRemoveUsers = ['171976fa8a8085fcdba']

client.addRemoveDevicesFromTag('tagtag', toAddUsers, toRemoveUsers,
    function (err, res) {
        if (err) {
            if (err instanceof JPush.APIConnectionError) {
                console.log(err.message)
            } else if (err instanceof JPush.APIRequestError) {
                console.log(err.message)
            }
        } else {
            console.log('success')
        }
    })

client.isDeviceInTag('tagtag', '171976fa8a8085fcdba', function (err, res) {
    if (err) {
        if (err instanceof JPush.APIConnectionError) {
            console.log(err.message)
        } else if (err instanceof JPush.APIRequestError) {
            console.log(err.message)
        }
    } else {
        console.log('isDeviceInTag :')
        console.log('got result:' + res['result'])
    }
})

client.deleteTag('tag1', null, function (err, res) {
    if (err) {
        if (err instanceof JPush.APIConnectionError) {
            console.log(err.message)
        } else if (err instanceof JPush.APIRequestError) {
            console.log(err.message)
        }
    } else {
        console.log('deleteTag :')
        console.log('success')
    }
})

client.getAliasDeviceList('alias1', null, function (err, res) {
    if (err) {
        if (err instanceof JPush.APIConnectionError) {
            console.log(err.message)
        } else if (err instanceof JPush.APIRequestError) {
            console.log(err.message)
        }
    } else {
        console.log('getAliasDeviceList :')
        console.log(res.registration_ids)
    }
})

client.deleteAlias('alias2', null, function (err, res) {
    if (err) {
        if (err instanceof JPush.APIConnectionError) {
            console.log(err.message)
        } else if (err instanceof JPush.APIRequestError) {
            console.log(err.message)
        }
    } else {
        console.log('deleteAlias :')
        console.log('success')
    }
})
